﻿using System;
using System.Collections.Generic;
using IListNode;
namespace JZ_54_er_cha_sou_suo_shu_de_di_kda_jie_dian_lcof
{
    class Program
    {
        static void Main (string[] args)
        {
            TreeNode node = new TreeNode (0);
            node.left = new TreeNode (5);
            node.right = new TreeNode (7);
            node.left.left = new TreeNode (9);
            node.left.right = new TreeNode (1);
            node.right.right = new TreeNode (2);

            Solution s = new Solution ();

            Console.WriteLine (s.KthLargest (node, 2));
        }
    }

    public class Solution
    {
        public int KthLargest (TreeNode root, int k)
        {
            Largest (root);
            nums.Sort ();
            return nums[nums.Count - k];
        }

        List<int> nums = new List<int> ();
        public void Largest (TreeNode root)
        {
            if (root == null) return;

            nums.Add (root.val);
            Largest (root.left);
            Largest (root.right);

            return;
        }
    }
}
